python123题目

您所在的位置:网站首页 python 复利计算 python123题目

python123题目

2023-12-14 15:47| 来源: 网络整理| 查看: 265

类型:数值运算

描述

在三行中依次输入初始存款金额,存款年限,年利率,每年末计一次利息并转为本金,计算并输出存款到期时的利息(不含本金,税前),结果保留2位小数。

复利法,每年末计算利息并自动转存:

F=P(1+i)^N

F:复利终值

P:本金

i:利率

N:利率获取时间的整数倍(年限)‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪‪‪‪‪‪‪

输入格式

第一行输入一个正整数(金额)‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪

第二行输入一个正整数(年限)‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪

第三行输入一个浮点数(年利率) ‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪

输出格式

利息=计算结果

示例 输入: 1000 3 0.025 输出:    利息=76.89 参考答案

这道题还是后面某道题忘了,巨恶心好吧,因为要保存到两位小数且计算精度很高,所以稍有一点错误就会过不了。

deposit = int(input())  # 存款金额本金 years = int(input())    # 存款年数 interest_rates = float(input())  # 年利率 new_deposit = deposit            # 初始本金 for i in range(years):           # 逐年计算新的一年的本息合计     new_deposit = new_deposit*(1 + interest_rates)  # 每年的本息合计总收益 interest = new_deposit - deposit  # 总收益中去掉初始本金结果为利息 print("利息={:.2f}".format(interest)) # 用幂运算实现 deposit = int(input())  # 存款金额本金 years = int(input()) interest_rates = float(input()) total = deposit * pow((1 + interest_rates), years) interest = total - deposit print("利息={:.2f}".format(interest))



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3